/**
 * 
 */
package de.wesemann.mediahandbook.le.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import de.wesemann.mediahandbook.le.R;

/**
 * @author Lars W.
 * 
 */
public class TitleWidget extends LinearLayout {
	private ImageView imageLeft;
	private ImageView imageSearch;
	private TextView title;
	private ProgressBar pBar;

	public TitleWidget(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public TitleWidget(Context context) {
		super(context);
		init();
	}

	// Init method of the TitleWidget which initializes all the widgets
	// after loading the layout file
	private void init() {
		// Inflate the title_widget.xml
		View view = inflate(getContext(), R.layout.title_widget, null);

		imageLeft = (ImageView) view.findViewById(R.id.title_icon);

		title = (TextView) view.findViewById(R.id.title_text);

		pBar = (ProgressBar) view.findViewById(R.id.title_progress);

		imageSearch = (ImageView) view.findViewById(R.id.title_search);

		// Add the view to the LinearLayout since TitleWidget extends
		// LinearLayout
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		addView(view, params);

	}

	public void setTitle(String text) {
		title.setText(text);
	}

	public String getTitle() {
		return title.getText().toString();
	}

	public void setLeftIcon(int resId) {
		imageLeft.setImageResource(resId);
	}

	public ProgressBar getProgressBar() {
		return this.pBar;
	}

	public void showProgressBar() {
		pBar.setVisibility(View.VISIBLE);
	}

	public void hideProgressBar() {
		pBar.setVisibility(View.INVISIBLE);
	}

	public void setSearchIcon(int resId) {
		imageSearch.setImageResource(resId);
	}

	public void hideSearchIcon() {
		imageSearch.setVisibility(GONE);
	}

	public void showSearchIcon() {
		imageSearch.setVisibility(VISIBLE);
	}
}
